home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-11-19 | 3.9 KB | 167 lines | [TEXT/PJMM] |
- unit NewFileUtils;
-
- { Created June 24, 1989, to aid Toolbox file calls. }
-
- interface
-
-
- uses
- HelloTabby, Globals;
-
- function MyWrite (FileRefNum: integer; var TheLine: str255): OSErr;
-
- function MyWriteLine (FileRefNum: integer; var TheLine: str255): OSErr;
-
- function AtEOF (fRefNum: Integer): Boolean;
-
- procedure FrameDItem (dLog: DialogPtr; iNum: integer);
-
- procedure MakeTextFile (filename: STR255);
-
- function Int2Char (Number: integer): char;
-
- function TwoDigit (Number: integer): string;
-
- procedure TimeStamp;
-
-
- implementation
-
- { ------------------------------------------------------ }
-
- procedure FrameDItem;
-
- var
- iBox: Rect;
- iType: integer;
- iHandle: Handle;
- oldPenState: PenState;
-
- begin
- GetPenState(oldPenState);
- GetDItem(dLog, iNum, iType, iHandle, iBox);
- InsetRect(iBox, -4, -4);
- PenSize(3, 3);
- FrameRoundRect(iBox, 16, 16);
- SetPenState(oldPenState)
- end;
-
- {----------------------------------------------------------------- }
-
- procedure MakeTextFile;
-
- { Procedure sets up QUED-compatible text file }
-
- var
- fndrInfo: FInfo;
-
- begin
- Err := GetFInfo(FileName, vRefNum, fndrInfo);
- if Err = noErr then
- begin
- fndrInfo.fdType := 'TEXT';
- fndrInfo.fdCreator := 'QED1';
- Err := SetFInfo(FileName, vRefNum, fndrInfo);
- end
- else
- Err := Create(FileName, vRefNum, 'QED1', 'TEXT');
- end;
-
- {----------------------------------------------------------------- }
-
- function Int2Char;
-
- { Function changes integer to character. }
-
- begin
- Int2Char := chr(Number + ord('0'));
- end;
-
- { ------------------------------------------------------ }
-
- function TwoDigit;
-
- { Function changes two-digit number to a two-character string. }
-
- begin
- TwoDigit := concat(Int2Char(Number div 10), Int2Char(Number mod 10));
- end;
-
- { ------------------------------------------------------ }
-
- procedure TimeStamp;
-
- var
- Today: DateTimeRec;
- ThisYear, ThisMonth, ThisDate, ThisHour, ThisMin, ThisSec: integer;
- ASCIIHour: string;
-
- begin
- GetTime(Today);
- with Today do
- begin
- ThisYear := Year;
- ThisMonth := Month;
- ThisDate := Day;
- ThisHour := Hour;
- ThisMin := Minute;
- ThisSec := Second
- end;
-
- { The TwoDigit function in the following section turns a two-digit integer }
- { into a two-character string. If there are fewer than two digits, the string }
- { contains a leading '0'. }
-
- ASCIIHour := TwoDigit(ThisHour); { This bit of nonsense is to get the Tabby Log output }
- if length(ASCIIHour) > 1 then { to match a Tabby convention: single-digit hours do }
- if (copy(ASCIIHour, 1, 1) = '0') then { not have leading zeroes, even though all other single }
- ASCIIHour := copy(ASCIIHour, 2, 1); { digit numbers do. }
-
- DateString := concat(TwoDigit(ThisMonth), '/', TwoDigit(ThisDate), '/', TwoDigit(ThisYear - 1900));
- TimeString := concat(TwoDigit(ThisHour), ':', TwoDigit(ThisMin), ':', TwoDigit(ThisSec));
- TabbyStamp := concat(DateString, ' ', ASCIIHour, ':', TwoDigit(ThisMin), ':', TwoDigit(ThisSec), ' ');
- end;
-
- { ------------------------------------------------------ }
-
- function AtEOF; { (fRefNum: Integer): Boolean; }
-
- var
- currPos, eofPos: LongInt;
-
- begin
- Err := GetFPos(fRefNum, currPos);
- Err := GetEOF(fRefNum, eofPos);
- AtEOF := currPos = eofPos
- end;
-
- { ------------------------------------------------------ }
-
- function MyWrite; { (FileRefNum: integer; var TheLine: str255): OSErr; }
-
- var
- TheLength: longint;
-
- begin
- TheLength := length(TheLine);
- MyWrite := FSWrite(FileRefNum, TheLength, Pointer(ord(@TheLine) + 1))
- end;
-
- { ------------------------------------------------------ }
-
- function MyWriteLine; { (FileRefNum: integer; var TheLine: str255): OSErr; }
-
- var
- CR: SignedByte;
- TheLength: longint;
-
- begin
- MyWriteLine := MyWrite(FileRefNum, TheLine);
- CR := 13;
- TheLength := 1;
- MyWriteLine := FSWrite(FileRefNum, TheLength, @CR)
- end;
-
- { ------------------------------------------------------ }
-
- end. { Unit }